<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>${siteName!""}|报价时效管理-添加报价时效</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/home/js/city-picker.data.js"></script>
    <script type="text/javascript" src="/home/js/city-picker.js"></script>
    <link rel="stylesheet" type="text/css" href="/home/branch/css/city-picker.css">

    <!--时间选择插件-->
    <link rel="stylesheet" href="/admin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a href="/system/index"><img src="/admin/images/logo-sidebar.png" title="${siteName!""}"
                                             alt="${siteName!""}"/></a>
            </div>
            <div class="lyear-layout-sidebar-scroll">
                <#include "../common/left-menu.ftl"/>
            </div>

        </aside>
        <!--End 左侧导航-->

        <#include "../common/header-menu.ftl"/>

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><h4>添加报价时效</h4></div>
                            <div class="card-body">
                                <form id="housing-characteristics-add-form" class="row">

                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">始发地</span>
                                        <input type="text" class="form-control required" readonly
                                               data-toggle="city-picker" id="origin" name="origin" value=""/>
                                    </div>

                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">目的地</span>
                                        <input type="text" class="form-control required"
                                               data-toggle="city-picker" id="destination" readonly name="destination" value=""/>
                                    </div>

                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">预计到达时间(天)</span>
                                        <input type="number" class="form-control required" onkeyup="value=value.replace(/[^\d]/g,'').replace(/^0{1,}/g,'')" name="eta" tips="请填写预计到达时间"  placeholder="请输入预计到达时间">
                                    </div>

                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">价格(KG/元)：</span>
                                        <input type="number" class="form-control required" id="pricePerKilogram"
                                               onkeyup="inputDouble(this)"
                                               name="pricePerKilogram" maxlength="8" tips="请填写价格(KG/元)"
                                               placeholder="请输入价格(KG/元)"/>
                                    </div>

                                    <div class="form-group col-md-12">
                                        <button type="button" class="btn btn-primary ajax-post"
                                                id="add-form-submit-btn">确 定
                                        </button>
                                        <button type="button" class="btn btn-default"
                                                onclick="javascript:history.back(-1);return false;">返 回
                                        </button>
                                    </div>
                                </form>

                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<#include "../common/footer.ftl"/>
<script src="/admin/bootstrap-datetimepicker/moment.min.js"></script>
<script src="/admin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="/admin/bootstrap-datetimepicker/locale/zh-cn.js"></script>
<script type="text/javascript" src="/admin/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/admin/js/main.min.js"></script>
<script type="text/javascript">

    function inputDouble(obj) {
        obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
        obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数

        if (obj.value.length > 10) {
            obj.value = ""
        }
    }



    $(document).ready(function () {
        //提交按钮监听事件
        $("#add-form-submit-btn").click(function () {
            if ($("#origin").val() == "") {
                showErrorMsg("请选择始发地");
                return;
            }
            if ($("#origin").val().split('/').length != 3){
                showErrorMsg("始发地请选择完整");
                return;
            }

            if ($("#destination").val() == "") {
                showErrorMsg("请选择目的地");
                return;
            }

            if ($("#destination").val().split('/').length != 3){
                showErrorMsg("目的地请选择完整");
                return;
            }

            if (!checkForm("housing-characteristics-add-form")) {
                return;
            }
            var data = $("#housing-characteristics-add-form").serialize();
            $.ajax({
                url: 'add',
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        showSuccessMsg('报价时效添加成功!', function () {
                            window.location.href = 'list';
                        })
                    } else {
                        showErrorMsg(data.msg);
                    }
                },
                error: function (data) {
                    alert('网络错误!');
                }
            });
        });

    });

</script>
</body>
</html>